package bishe;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.*;

public class Login {

	public static void main(String[] args) throws IOException {
		// TODO 自动生成的方法存根
		// 初始化面板
		JFrame MainMenu = new JFrame("登录界面");
		MainMenu.setLayout(new BorderLayout());
		MainMenu.setSize(400, 500);
		MainMenu.setLocation(300, 200);
		MainMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// 初始化顶部面板
		JPanel welcome = new JPanel();
		welcome.setLayout(null);
		welcome.setPreferredSize(new Dimension(100, 80));
		JLabel wel = new JLabel("欢迎光临");
		wel.setFont(new Font("楷体", Font.PLAIN, 40));
		wel.setBounds(110, -10, 300, 120);
		welcome.add(wel);
		// 初始化中间面板
		JPanel userlogin = new JPanel();
		userlogin.setLayout(null);// 取消默认布局
		userlogin.setPreferredSize(new Dimension(200, 120));
		JLabel ton2 = new JLabel("用户名");
		ton2.setBounds(20, -10, 100, 50);
		JTextField txtname = new JTextField(20);
		txtname.setBounds(70, 0, 250, 30);
		JLabel ton3 = new JLabel("密     码");
		ton3.setBounds(20, 40, 100, 50);
		JTextField txtpassword = new JTextField(20);
		txtpassword.setBounds(70, 50, 250, 30);
		JRadioButton ids = new JRadioButton("管理员");
		ids.setBounds(90, 120, 100, 40);
		JRadioButton idss = new JRadioButton("用   户");
		idss.setBounds(230, 120, 100, 40);
		ButtonGroup group = new ButtonGroup();
		group.add(ids);
		group.add(idss);
		// 底部面板
		JPanel login = new JPanel();
		login.setLayout(null);
		login.setPreferredSize(new Dimension(350, 120));
		JButton ton1 = new JButton("登录");
		JButton ton4 = new JButton("注册");
		ton1.setBounds(30, 60, 100, 40);
		ton4.setBounds(250, 60, 100, 40);
		login.add(ton1);
		login.add(ton4);
		userlogin.add(ton2);
		userlogin.add(txtname);
		userlogin.add(ton3);
		userlogin.add(ids);
		userlogin.add(idss);
		userlogin.add(txtpassword);
		MainMenu.add(welcome, BorderLayout.PAGE_START);
		MainMenu.add(userlogin, BorderLayout.CENTER);
		MainMenu.add(login, BorderLayout.PAGE_END);
		MainMenu.setVisible(true);
		// 注册监听器
		ton1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO 自动生成的方法存根
				try {
					if (ids.isSelected()) {
						if (logincheck.admincheck(txtname.getText(), txtpassword.getText())) {
							MainMenu.dispose();
							Admin.Administrator();
						}
					}
					if (idss.isSelected()) {
						if (logincheck.usercheck(txtname.getText(), txtpassword.getText())) {
							MainMenu.dispose();
							user.Customer();

						}

					}
				} catch (IOException e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
			}
		});

	}

}
